package com.gzu.shop.common;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Clown
 */
@Tag(name = "统一返回值")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    @Parameter(description = "返回码")
    private String code;
    @Parameter(description = "消息")
    private String message;
    @Parameter(description = "数据")
    private T data;

    public static <T> Result<T> success(ResultStatus resultStatus) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = resultStatus.getDescription();
        return result;
    }

    // 成功请求
    public static <T> Result<T> success(ResultStatus resultStatus, T object) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = resultStatus.getDescription();
        result.data = object;
        return result;
    }


    public static <T> Result<T> success(ResultStatus resultStatus, T oject, String msg) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = msg;
        result.data = oject;
        return result;
    }



    // 错误请求
    public static <T> Result<T> error(ResultStatus resultStatus) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = resultStatus.getDescription();
        return result;
    }

    public static <T> Result<T> error(ResultStatus resultStatus, T object) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = resultStatus.getDescription();;
        result.data = object;
        return result;
    }
    public static <T> Result<T> error(ResultStatus resultStatus, String msg) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = msg;
        return result;
    }

    public static <T> Result<T> error(ResultStatus resultStatus, T oject, String msg) {
        Result<T> result = new Result<>();
        result.code = resultStatus.getCode();
        result.message = msg;
        result.data = oject;
        return result;
    }

}
